package com.kang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kang.entity.Folder;
import com.kang.entity.FolderCarousel;
import com.kang.mapper.FolderCarouselMapper;
import com.kang.service.FolderCarouselService;
import com.kang.vo.FolderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;

@Service
public class FolderCarouselServiceImpl extends ServiceImpl<FolderCarouselMapper, FolderCarousel> implements FolderCarouselService {

    @Autowired
    private FolderCarouselMapper folderCarouselMapper;

    @Override
    public Integer insertFolderCarousel(FolderCarousel folderCarousel) {
        folderCarousel.setCreateTime(new Date());
        folderCarousel.setUpdateTime(new Date());
        return folderCarouselMapper.insert(folderCarousel);
    }

    @Override
    public Integer deleteFolderCarousel(FolderCarousel folderCarousel) {
        System.out.println("99999999");


        System.out.println(111);
        return folderCarouselMapper.deleteById(folderCarousel.getId());
    }

    @Override
    public Page<FolderCarousel> getFolderCarouselPage(FolderVo vo) {
        Page<FolderCarousel> page = new Page<>(vo.getPageNum(), vo.getPageSize());
        QueryWrapper<FolderCarousel> wrapper = new QueryWrapper<>();
        wrapper.eq(!StringUtils.isEmpty(vo.getFolderName()),"folder_name",vo.getFolderName());
        wrapper.between(!StringUtils.isEmpty(vo.getStartTime()),"create_time",vo.getStartTime(),vo.getEndTime());
        return folderCarouselMapper.selectPage(page,wrapper);
    }
}
